package org.zhouhe.tag.security;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.BodyTagSupport;

import org.zhouhe.util.Constant;
import org.zhouhe.vo.User;

import com.opensymphony.xwork2.ActionContext;

@SuppressWarnings( { "serial" })
public class ByUser extends BodyTagSupport {
	private String loginName;
	private User user;

	@Override
	public void doInitBody() throws JspException {
		Map<String, Object> sessionMap = ActionContext.getContext().getSession();
		user = (User) sessionMap.get(Constant.SESSION_KEY_USER_INFO);
	}

	@Override
	public int doStartTag() throws JspException {
		List<String> list = Arrays.asList(loginName.replaceAll(" ", "").split(","));
		if (user != null && list.contains(user.getLoginName())) {
			return EVAL_BODY_INCLUDE;
		}
		return SKIP_BODY;
	}

	public String getLoginName() {
		return loginName;
	}

	public void setLoginName(String loginName) {
		this.loginName = loginName;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}
}
